package geguol.cc.widgetapplication.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.widget.LinearLayout;
import android.widget.RadioGroup;
import java.util.ArrayList;
import java.util.List;
import geguol.cc.widgetapplication.R;

/**
 * 作者  格锅
 * 时间  2017/4/19 21:23
 * 文件  WidgetApplication
 * 描述  表情布局
 */

public class FaceLayout extends LinearLayout {
	private RadioGroup group;
	private List<Integer> childs=new ArrayList<>();
	public FaceLayout(Context context) {
		super(context);
		init();
	}

	public FaceLayout(Context context, AttributeSet attrs) {
		super(context, attrs);
		init();
	}

	private boolean isClickable = true;
	private void init() {
		LayoutInflater layoutInflater =  (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		layoutInflater.inflate(R.layout.five_radio, this,true);
		group = (RadioGroup) findViewById(R.id.radio_group);
		childs.add(R.id.sad);
		childs.add(R.id.sad);
		childs.add(R.id.crazy);
		childs.add(R.id.cry);
		childs.add(R.id.smile);
		group.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
			@Override
			public void onCheckedChanged(RadioGroup group, int checkedId) {
				if (listener!=null){
					listener.onChosed(childs.indexOf(checkedId));
				}
			}
		});
	}

	public void setViewClickable(boolean Clickable){
		this.isClickable = Clickable;
	}

	@Override
	public boolean onInterceptTouchEvent(MotionEvent ev) {
		System.out.println("是否拦截 "+!isClickable);
		return !isClickable;
	}

	public void setValue(int value){
		int temp = value%5;
		group.check(childs.get(temp));
	}

	public interface Clicklistener{
		void onChosed(int index);
	}


	private Clicklistener listener;

	public void setClickLister(Clicklistener l){
		this.listener = l;
	}


}
